﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 图书借阅系统
{
    public partial class 修改图书 : System.Web.UI.Page
    {
        private void BindDropDownList1()
        {
            string ta = "select distinct 分类 from 图书";
            DropDownList1.DataSource = Connection.getData(ta);
            DropDownList1.DataTextField = "分类";//文本内容字段
            DropDownList1.DataValueField = "分类"; //值字段
            DropDownList1.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {           
            BindDropDownList1();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Session["BookId"].ToString());
            
            String name = TextBox1.Text.Trim();
            
            int sum = Convert.ToInt32(TextBox2.Text.Trim());
            
            int num = Convert.ToInt32(TextBox3.Text.Trim());

            string tt = "select 书名,分类,总数,实际数量 from 图书 where id = "+ id+"";
            
            if (Connection.getData(tt)!=null)
            {   
                

                String ss = "update 图书 set 书名='" + name + "',分类='" + DropDownList1.SelectedValue + "',总数='" + sum + "',实际数量 = '" + num + "' where id = '" + id+ "'";
                Label2.Text = "修改成功";
                Connection.setData(ss);
                
            }
            else {
                
                    Label2.Text = "修改失败";
                    
                
            }
           
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "";
            DropDownList1.SelectedValue = "计算机类";
            TextBox2.Text = "";
            TextBox3.Text = "";
            Label2.Text = "";
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("管理员书名查询.aspx");
        }
    }
}